package com.cx.service.admin.basic.impl;

import com.cx.dao.impl.ChainJKTDaoSupport;
import com.cx.service.admin.basic.ChainBasicOrgManager;
import org.cx.entity.Page;
import org.cx.entity.PageData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("chainBasicOrgService")
public class ChainBasicOrgService implements ChainBasicOrgManager {
    @Resource(name = "chainJKTDaoSupport")
    private ChainJKTDaoSupport chainJKTDao;

    @Override
    public List<PageData> findOrgDetailPage(Page pg) {
        List<PageData> list = (List<PageData>) chainJKTDao.findForList("OrgMapper.findOrgDetailPage", pg);
        return list;
    }

    @Override
    public List<PageData> findOrgList(PageData pd) {
        List<PageData> list = (List<PageData>) chainJKTDao.findForList("OrgMapper.selectOrgPdByPd", pd);
        return list;
    }

    @Override
    public PageData findOrgByPageDate(PageData pd) {
        pd = (PageData) chainJKTDao.findForObject("OrgMapper.selectOrgByID", pd);
        return pd;
    }

    @Override
    public Integer  insertOrg(PageData pd) {
        Integer result  =(Integer) chainJKTDao.save("OrgMapper.insertOrg",pd);
        return result;
    }

    @Override
    public Integer updateOrg(PageData pd) {
        Integer result =(Integer) chainJKTDao.update("OrgMapper.updateOrg",pd);
        return result;
    }

    @Override
    public String findOrgIdsByParentId(PageData pd) {
        //findOrgIdsByParentId
        PageData idsPd = (PageData) chainJKTDao.findForObject("OrgMapper.findOrgIdsByParentId",pd);
        return idsPd == null?null:idsPd.getString("ids");
    }

    @Override
    public List<PageData> findAllOrgsByUserorg(PageData pd) {

        return (List<PageData>) chainJKTDao.findForList("OrgMapper.findAllOrgsByUserorg", pd);
    }
    
    @Override
    public PageData selectOrgByTopOrgIdAndID(PageData pd) {
        pd = (PageData) chainJKTDao.findForObject("OrgMapper.selectOrgByTopOrgIdAndID", pd);
        return pd;
    }
}
